package com.xiguanlezz.cn.consumer.context;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.xiguanlezz.cn.consumer.future.RpcFuture;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/7 14:48
 * @Description：Rpc异步上下文
 */
public class RpcContext {
    private final InheritableThreadLocal<RpcFuture> RPC_FUTURE_INHERITABLE_THREAD_LOCAL = new InheritableThreadLocal<>();
//    private final TransmittableThreadLocal<RpcFuture> RPC_FUTURE_TRANSMITTABLE_THREAD_LOCAL = new TransmittableThreadLocal<>();

    private static final RpcContext AGENT = new RpcContext();


    private RpcContext() {
    }

    public static RpcContext getContext() {
        return AGENT;
    }

    public void setRpcFuture(RpcFuture rpcFuture) {
        RPC_FUTURE_INHERITABLE_THREAD_LOCAL.set(rpcFuture);
    }

    public RpcFuture getRpcFuture() {
        return RPC_FUTURE_INHERITABLE_THREAD_LOCAL.get();
    }

    public void removeRpcFuture() {
        RPC_FUTURE_INHERITABLE_THREAD_LOCAL.remove();
    }
}
